import{s as i,bq as B,br as C,a2 as G,d as I,aQ as N,b as _,o as p,a as x,c as U,e as w,t as m,u as n,w as k,f as V,g as b,B as T,F as v}from"./DrFvzlh8agutd.js";import{m as D,g as S}from"./CZ0h8Jpj3Xa3MT.js";import{U as L}from"./CwAUA1OU17ghgo.js";import{K as h}from"./MpnPZlTSagutd.js";import{a as A}from"./DZFz6IIX1esOcA.js";import{a as E}from"./sf48gIWk3aD96J.js";import{_ as F}from"./BfQegiIr3PfrX1.js";import{_ as M}from"./JLTbM6jQPQMM7.js";const R="r2gt:///invoices",$="doc";async function q(){E("Sync GrandTotal",async d=>{if(!i.workspace)return;const l=await B(R);if(l){const e=[],f=D.parse(l),u=S($,"refGT"),g=S("contact","refGT");for(const t of f){const o=t.recipient?.uid;let a=g[o??""];o!=null&&a==null&&(a=h(),g[o]=a,i.workspace.createItem({_id:a,_type:"contact",title:t.recipient?.name??t.clientName}));const s=u[t.uid],r=s!=null,c=s??h(),y={_id:c,_type:$,credit:!0,title:t.name,contact:a,gross:+t.gross,net:+t.net,currency:t.currency,date:C(new Date(t.dateSent)),positions:{}};e.push({update:r,id:c,url:t.url,item:y}),r||i.workspace.createItem(y)}d.setMax(e.length);for(const{id:t,url:o,update:a}of e){if(!a){const s=await G(`r2gt:///download?${L({url:o})}`);if(s!=null&&s.length>0){const r=await i.workspace?.sync?.createAsset(s,{type:"application/pdf"});if(r){const c=A(r);c&&i.workspace?.updateItem(t,{asset:c})}}}d.incResolved()}}})}const K={key:0},X=I({__name:"app-settings-grandtotal",setup(d){const l=N();return(e,f)=>(p(),_(v,null,[x("h3",null,m(e.$t("settings.grandtotal.title")),1),n(l)?(p(),U(n(M),{key:0,title:e.$t("settings.grandtotal.syncActionTitle")},{default:k(({id:u})=>[V(n(F),{onClick:n(q)},{default:k(()=>[b(m(e.$t("settings.grandtotal.syncNow")),1)]),_:1},8,["onClick"]),n(T).gtLastSync?(p(),_("p",K,m(e.$t("settings.grandtotal.lastSync",[new Date(n(T).gtLastSync).toLocaleString()])),1)):w("",!0)]),_:1},8,["title"])):w("",!0)],64))}});export{X as default};